<!-- 添加系统基础配置 -->
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>添加系统基础配置</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <link rel="stylesheet" href="/lib/layui-v2.6.8/css/layui.css" media="all" />
    <link rel="stylesheet" href="/css/public.css" media="all" />
    <style>
        body {
            background-color: #ffffff;
        }

        .layui-elem-quote {
            padding: 10px;
            border-left: 5px solid #009688;
        }
    </style>
</head>

<body>
    <blockquote class="layui-elem-quote layui-text">系统基础配置，请联系开发人员添加</blockquote>
    <div class="layui-form layuimini-form" lay-filter="addForm">
        <!-- 表单字段 -->
        <div class="layui-form-item">
            <label class="layui-form-label required">参数类型</label>
            <div class="layui-input-block">
                <input type="text" id="type" name="type" lay-verify="required" lay-reqtext="参数类型不能为空" placeholder="请输入" value="" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">参数名</label>
            <div class="layui-input-block">
                <input type="text" id="name" name="name" lay-verify="required" lay-reqtext="参数名不能为空" placeholder="请输入" value="" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">参数值</label>
            <div class="layui-input-block">
                <input type="text" id="val" name="val" lay-verify="required|number" lay-reqtext="参数值不能为空" placeholder="请输入" value="" class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea id="remark" name="remark" placeholder="请输入" value="" class="layui-textarea"></textarea>
            </div>
        </div>
        <!-- 确认保存按钮 -->
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: right;">
                <button class="layui-btn layui-btn-primary layui-layer-close1" id="cancel">取消</button>
                <button class="layui-btn" lay-submit lay-filter="saveBtn"><i class="layui-icon"></i>确认保存</button>
            </div>
        </div>
    </div>

    <!-- 后端接口定义 -->
    <script src="/js/api-route.js"></script>
    <!-- 页面事件处理 -->
    <script src="/lib/layui-v2.6.8/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['jquery', 'layer', 'form'], function () {
            var $ = layui.jquery,
                layer = layui.layer,
                form = layui.form;

            // 监听提交
            form.on('submit(saveBtn)', function (data) {
                // Ajax提交数据到后台
                $.ajax({
                    url: $api.baseconfig.add,
                    type: 'POST',
                    data: JSON.stringify(data.field), // 将对象转换为JSON字符串传递
                    dataType: 'JSON',
                    contentType: "application/json", // 指定请求方式为JSON
                    // headers: {
                    //     token: localStorage.token, // 接口请求头必须携带Token参数（登录后从本地存储中获取token）
                    // },
                    success: function (res) {
                        if (res.code == 0) {
                            layer.msg('添加成功', {
                                icon: 6
                            });
                            parent.layui.table.reload('currentTable', {
                                page: {
                                    curr: 1
                                }
                            });
                            setTimeout(function () {
                                window.parent.layer.closeAll();
                                return false;
                            }, 500);
                        } else {
                            layer.msg('添加失败', {
                                icon: 5
                            });
                            parent.layui.table.reload('currentTable', {
                                page: {
                                    curr: 1
                                }
                            });
                            setTimeout(function () {
                                window.parent.layer.closeAll();
                                return false;
                            }, 500);
                        }
                    },
                    error: function (res) {
                        layer.msg('服务器开小差了', {
                            offset: '15px',
                            icon: 2,
                            time: 1500,
                        });
                    }
                });
            });

            // 点击取消按钮
            $('#cancel').click(function () {
                // 关闭当前弹出页面
                window.parent.layer.closeAll();
                return false;
            });

        });
    </script>
</body>

</html>